<?php
	include_once('auth.php');
		
	include_once('config.php');
?>
<!DOCTYPE html>
<html>
	<head>
		<title>weZze-admin</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
        <link rel="shortcut icon" href="/favicon.ico" />
        <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
        <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen" />
        <script type = "text/javascript" src = "http://code.jquery.com/jquery-1.7.2.js"></script>
        <script type = "text/javascript" src = "js/script.js"></script>
        <script type = "text/javascript" src = "js/bootstrap.min.js"></script>
        <script type = "text/javascript" src = "js/tipsy.js"></script>
	</head>
	
	<body>
		<div class = "sendData sendImg"></div>
		<div class = "row-fluid show-grid logoutButton">
			<div class = "span1 offset11"><a href = "?do=logout"><span class="label label-info">Выйти</span></a></div>
		</div>
		<div class = "row-fluid show-grid">	
			<div class = "span8">
<?php
			$videos = getAllVideo();
?>
				<h4>Все видео:</h4>
				<table id = "videoTable" class = "table table-striped table-bordered table-condensed">
					<tr>
						<th>
							#
						</th>
						<th>
							Название
						</th>
						<th>
							Код
						</th>
						<th>
							Ролик
						</th>
						<th>
							Превью
						</th>
						<th>
							Категория
						</th>
						<th>
							Страница видео
						</th>
						<th>
							Управление
						</th>
					</tr>
					
<?php
					if (is_array($videos) > 0)
					{
						$i = 1;
						foreach ($videos as $one_video)
						{
?>
					<tr>
						<td>
							<?= $i; ?>
						</td>
						<td>
							<?= $one_video['name']; ?>
						</td>
						<td>
							<?= $one_video['code']; ?>
						</td>
						<td>
							<a href = "<?= $one_video['link']; ?>" target = "blank"><?= $one_video['link']; ?></a>
						</td>
						<td>
							<a href = "<?= $one_video['preview_link']; ?>" target = "blank"><?= $one_video['preview_link']; ?></a>
						</td>
						<td>
							<?= getVideoCategoryName ($one_video['id'], 'ru'); ?>
						</td>
						<td class = "align_center">
							<?php
								$video_url = 'http://'.$_SERVER["HTTP_HOST"].'/#!/video/'.$one_video['id'];
								echo '<a href="'.$video_url.'"><i class="icon-arrow-right"></i></a>'; 
							?>
						</td>
						<td class = "align_center">
							<i class="icon-refresh refreshImg" original-title="Обновить изображение"></i>
							<input type = "hidden" name = "link" value = "<?= $one_video['preview_link']; ?>" />
							<i class="icon-remove delVideo" original-title="Удалить видео"></i>
							<input type = "hidden" name = "videoID" value = "<?= $one_video['id']; ?>" />
						</td>
					</tr>		
<?php
							$i++;
						}
					}
?>
				</table>
			</div>
			
			<div class = "span4">
				<div id = "addVideoDiv">
					<div class = "sendData sendVideo"></div>
					<form name = "addVideo" id = "addVideoForm" url = 'add_video_controller.php'>
						<h4>Добавить видео:</h4>
						<table id = "addVideoTable" >
							<tr class = "control-group">
								<th>Название:</th>
								<td><input type = "text" name = "vName" class = "required" /></td>
							</tr>
							<tr class = "control-group">
								<th>Код:</th>
								<td><input type = "text" name = "vCode" class="input-mini required" /></td>
							</tr>
							<tr class = "control-group">
								<th>Ролик:</th>
								<td><input type = "url" name = "vLink" class = "required" /></td>
							</tr>
							<tr class = "control-group">
								<th>Превью:</th>
								<td><input type = "url" name = "vPreview" class = "required" /></td>
							</tr>
							<tr class = "control-group">
								<th>Количество фото/видео вставок:</th>
								<td><input type = "text" name = "vPhoto" class="input-mini" /></td>
							</tr>
							<tr class = "control-group">
								<th>Количество текстовых вставок:</th>
								<td><input type = "text" name = "vText" class="input-mini" /></td>
							</tr>
							<tr class = "control-group">
								<th>Описание:</th>
								<td><textarea name = "vDesc" class="input-xlarge"></textarea></td>
							</tr>
							<tr class = "control-group">
								<th>Категория:</th>
								<td><select name = "vCat" class = "required">
<?php
							foreach (getAllCategoriesID() as $cat_id)
							{
?>
								<option value = "<?= $cat_id; ?>"><?= getCategoryNameByID($cat_id, 'ru'); ?></option>
<?php
							}
?>
								</select></td>
							</tr>
							<tr class = "control-group">
								<th><a href = "/admin/tags.php" original-title="Перейти на страницу создания тегов" class = "tipsyLink">Теги:</a></th>
								<td>
<?php
							foreach (getAllTagsID() as $tag_id)
							{
?>
								<label class = "checkbox"><input name = "vTags[]" type = "checkbox" value = "<?= $tag_id; ?>"><?= getTagNameByID($tag_id, 'ru'); ?></label>
<?php
							}
?>
								</td>
							</tr>
							<tr>
								<td colspan = 2 class = "align_right"><button type = "submit" class = "btn btn-primary">Добавить</button></td>
							</tr>
						</table>
					</form>
				</div>
			</div>
		</div>
	</body>
</html>